import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

void main () => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  double topDistance = 10.0;
  double leftDistance = 160.0;
  var positionList = <double>[];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(title: const Text("手势检测"),),
            body: Stack(
              children: <Widget>[
                Positioned(
                  top: topDistance,
                  left: leftDistance,

                  child: GestureDetector(
                    child: const CircleAvatar(
                      child: Text("A"),
                      backgroundColor: Colors.blue,
                    ),

                    onPanDown: (DragDownDetails e) {
                      //打印手指按下的位置(相对于屏幕)
                      print("用户手指按下：${e.globalPosition}");
                      RenderErrorBox.backgroundColor = Colors.white;
                    },

                    //第一种 垂直方向滑动、拖动
                    onVerticalDragUpdate:(DragUpdateDetails e) {
                      //用户手指滑动时，更新偏移，重新构建
                      setState(() {
                        var temp = topDistance;
                        // var temp;
                        topDistance += e.delta.dy;
                        temp = topDistance - temp;
                        print(temp);
                        // positionList.add(temp);
                      });
                    },

                    //滑动结束触发此回调
                    onPanEnd: (DragEndDetails e){
                      //打印滑动结束时在x、y轴上的速度
                      print("滑动结束，开始匹配");
                      print(positionList);
                    },
                  ),
                )
              ],
            )
        )
    );
  }
}










// import 'package:flutter/material.dart';
//
// void main() => runApp(const MyApp());
//
//
// class MyApp extends StatelessWidget {
//   const MyApp({Key? key}) : super(key: key);
//
//   @override
//   Widget build(BuildContext context) {
//     // TODO: implement build
//     return MaterialApp(
//       title: 'draw line',
//       home: Scaffold(
//         appBar: AppBar(
//           title: const Text(
//             'test: draw line',
//             style: TextStyle(color: Colors.white),
//           ),
//         ),
//         body: Center(
//           child: SizedBox(
//             width: 500,
//             height: 500,
//             child: CustomPaint(
//               painter: LinePainter(),
//               child: const Center(
//                 child: Text(
//                   'test',
//                   style: TextStyle(
//                     fontSize: 38.0,
//                     fontWeight: FontWeight.w600,
//                     color: Colors.black,
//                   ),
//                 ),
//               ),
//             ),
//           ),
//         ),
//       ),
//     );
//   }
// }
//
// class LinePainter extends CustomPainter {
//   final Paint _paint = Paint()
//       ..color = Colors.black
//       ..strokeCap = StrokeCap.square
//       ..isAntiAlias = true
//       ..strokeWidth = 3.0
//       ..style = PaintingStyle.stroke;
//
//   @override
//   void paint(Canvas canvas, Size size) {
//     canvas.drawLine(Offset(300.0, 20.0), Offset(300.0, 500.0), _paint);
//   }
//
//   @override
//   bool shouldRepaint(CustomPainter old){
//     return false;
//   }
// }
//
